number=2521;
name="frame"+num2str(number)+"(1).jpg";
disp(name);
I=imread(name);
%subplot(2,2,1),
imshow(I);
%thresh = graythresh(I);     %自动确定二值化阈值
I1 = im2bw(I,0.27);%对图像二值化
%subplot(2,2,2),
figure;
imshow(I1);
I2=~I1;
subplot(2,2,3),
imshow(I2);
[L1,num1] = bwlabel(I2,8);  %对联通区域进行标记
S=regionprops(L1,'Area');  %标记区域 
P1=regionprops(L1,'Perimeter'); %标记区域的周长
bw2 = ismember(L1, find([S.Area] >= 1000 & [S.Area] <= 3000) );
subplot(2,2,4);
imshow(bw2);
[L2,num2] = bwlabel(bw2);
S2=regionprops(L2,'Area');  %标记区域 
P2=regionprops(L2,'Perimeter');
areas = cat(1, S2.Area);
perimeters=cat(1, P2.Perimeter);
circular=4*pi*areas./(perimeters.*perimeters);
L2(find(L2~=find(circular>0.6)))=0;
figure;
imshow(L2);
%r=ismember(L1,find([P2.Perimeter./(2*(S2.Area*pi)^(1/2))]>0.6))
%imshow(r);
